/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cw.entity;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author VinhTC
 */
@Entity
@Table(name = "tblGameResult")
@NamedQueries({
    @NamedQuery(name = "GameResult.findAll", query = "SELECT g FROM GameResult g"),
    @NamedQuery(name = "GameResult.findByUserId", query = "SELECT g FROM GameResult g WHERE g.userId = :userId"),
    @NamedQuery(name = "GameResult.findByUserName", query = "SELECT g FROM GameResult g WHERE g.userName = :userName"),
    @NamedQuery(name = "GameResult.findByScore", query = "SELECT g FROM GameResult g WHERE g.score = :score"),
    @NamedQuery(name = "GameResult.findBySpentTime", query = "SELECT g FROM GameResult g WHERE g.spentTime = :spentTime"),
    @NamedQuery(name = "GameResult.findByPlayTime", query = "SELECT g FROM GameResult g WHERE g.playTime = :playTime")})
public class GameResult implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "UserId")
    private Integer userId;
    @Basic(optional = false)
    @Column(name = "UserName")
    private String userName;
    @Basic(optional = false)
    @Column(name = "Score")
    private int score;
    @Basic(optional = false)
    @Column(name = "SpentTime")
    private int spentTime;
    @Column(name = "PlayTime")
    @Temporal(TemporalType.TIMESTAMP)
    private Date playTime;
    @JoinColumn(name = "PuzzleId", referencedColumnName = "PuzzleId")
    @ManyToOne(optional = false)
    private Puzzle puzzle;

    public GameResult() {
    }

    public GameResult(Integer userId) {
        this.userId = userId;
    }

    public GameResult(Integer userId, String userName, int score, int spentTime) {
        this.userId = userId;
        this.userName = userName;
        this.score = score;
        this.spentTime = spentTime;
    }

    public Integer getUserId() {
        return userId;
    }

    public void setUserId(Integer userId) {
        this.userId = userId;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public int getScore() {
        return score;
    }

    public void setScore(int score) {
        this.score = score;
    }

    public int getSpentTime() {
        return spentTime;
    }

    public void setSpentTime(int spentTime) {
        this.spentTime = spentTime;
    }

    public Date getPlayTime() {
        return playTime;
    }

    public void setPlayTime(Date playTime) {
        this.playTime = playTime;
    }

    public Puzzle getPuzzle() {
        return puzzle;
    }

    public void setPuzzle(Puzzle puzzle) {
        this.puzzle = puzzle;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (userId != null ? userId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof GameResult)) {
            return false;
        }
        GameResult other = (GameResult) object;
        if ((this.userId == null && other.userId != null) || (this.userId != null && !this.userId.equals(other.userId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "cw.entity.GameResult[userId=" + userId + "]";
    }

}
